package com.xxx.netty.inoutbound.client;

import com.xxx.netty.inoutbound.MyByteToLongDecoder;
import com.xxx.netty.inoutbound.MyLongToByteEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * client端初始化器
 */
public class MyClientInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 在初始化器里往pipeline添加入栈handler
        ChannelPipeline pipeline = ch.pipeline();
        // 入栈handler进行解码（入栈都必须先进行解码）
        pipeline.addLast(new MyByteToLongDecoder());
        // 先添加自定义编码器
        pipeline.addLast(new MyLongToByteEncoder());
        // 后添加添加client业务处理器
        pipeline.addLast(new MyClientHandler());

    }
}
